<html>
<head><meta charset="utf-8"><title>expansion ordering · t-compiler/help-wanted · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/index.html">t-compiler/help-wanted</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html">expansion ordering</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215690682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215690682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215690682">(Nov 05 2020 at 09:58)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> I am looking at some of the issues regarding proc macro expansion ordering and I would like some knowledge on how it works currently. Reference: <a href="https://github.com/rust-lang/rust/issues/67839#issuecomment-722271258">https://github.com/rust-lang/rust/issues/67839#issuecomment-722271258</a></p>



<a name="215690748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215690748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215690748">(Nov 05 2020 at 09:58)</a>:</h4>
<p>I assume the ordering doesn't work currently in the order the attributes are specified.</p>



<a name="215690771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215690771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215690771">(Nov 05 2020 at 09:58)</a>:</h4>
<p>And it looks like <code>derive</code> is also being expanded first before everything else</p>



<a name="215690812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215690812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215690812">(Nov 05 2020 at 09:59)</a>:</h4>
<p>Does <code>derive(Foo, Bar)</code> expand <code>Foo</code> first and then <code>Bar</code>?</p>



<a name="215769234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215769234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215769234">(Nov 05 2020 at 20:25)</a>:</h4>
<p>Derive macros inside <code>derive(...)</code> are expanded left-to-right, yes.<br>
We don't currently have issues with this case.</p>



<a name="215769348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215769348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215769348">(Nov 05 2020 at 20:26)</a>:</h4>
<p><code>derive</code> itself is expanded last, that's why you cannot write other attribute macros after it. This needs fixing.</p>



<a name="215769574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215769574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215769574">(Nov 05 2020 at 20:28)</a>:</h4>
<p>Inert attributes are reordered in some way due to expansion of macro attributes around them, this also needs fixing and it's the focus of the linked issue.</p>



<a name="215781830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/212497-t-compiler/help-wanted/topic/expansion%20ordering/near/215781830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/212497-t-compiler/help-wanted/topic/expansion.20ordering.html#215781830">(Nov 05 2020 at 22:20)</a>:</h4>
<p>Huh, weird. I have a <code>proc_macro_attribute</code> when used on a struct before <code>derive(Serialize)</code>, it doesn't seem to get the <code>derive</code> attribute in <code>input.attrs</code>. Which is why I assumed <code>derive</code> expansion is happening first.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>